package com.zjjk.transfer.app;

import com.zjjk.transfer.source.entity.SourceDish;
import com.zjjk.transfer.source.entity.SourceDishMeal;
import com.zjjk.transfer.source.service.SourceDishMealService;
import com.zjjk.transfer.source.service.SourceDishService;
import com.zjjk.transfer.target.entity.TargetDish;
import com.zjjk.transfer.target.service.TargetDishService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DishTransfer extends BaseTransfer<SourceDish, TargetDish, SourceDishService, TargetDishService> {

    @Autowired
    private SourceDishMealService sourceDishMealService;

    @Override
    protected TargetDish convert(SourceDish source) {
        TargetDish target = new TargetDish();
        BeanUtils.copyProperties(source,target);
        target.setId(Long.valueOf(source.getId()));
        target.setDishCategoryId(Long.valueOf(source.getMealType()));
        SourceDishMeal byId = sourceDishMealService.getById(source.getMealType());
        target.setMealTimeFrame(byId.getTimeFrame());
        target.setMealType(byId.getType());
        target.setMealBoxFee(source.getMealsFee());
        target.setDeleted(0);
        return target;
    }
}
